#include "RTC.h"

void RTC_Init(void)
{
		RTC_Config_T Struct;
    /* Enable PMU periph clock */
    RCM_EnableAPB1PeriphClock(RCM_APB1_PERIPH_PMU);
    /* Enable Access Backup */
    PMU_EnableBackupAccess();
    /* Enable LSI */
    RCM_EnableLSI();
    /* wait until LSI is ready */
    while (RCM_ReadStatusFlag(RCM_FLAG_LSIRDY) == RESET);
    /* Select LSI as RTC clock */
    RCM_ConfigRTCCLK(RCM_RTCCLK_LSI);
    /* Enable RTC clock */
    RCM_EnableRTCCLK();
    RTC_DisableWriteProtection();
    RTC_WaitForSynchro();
    /* LSI */
    RTC_ConfigStructInit(&Struct);
    Struct.AsynchPrediv = 0X63;
    Struct.SynchPrediv  = 0X18F;
    RTC_Config(&Struct);
		RTC_EnableInit(); 
}



void RTC_Cali(u8 time[])                //用来时间校准，放到涂鸦校准时间函数里面 
{
			RTC_DATE_T DateStruct;
			RTC_TIME_T TimeStruct;	
	
	
			TimeStruct.minutes = time[5];	
			TimeStruct.seconds = time[6];	
			DateStruct.year = time[1];		
			DateStruct.month = time[2];		
			DateStruct.date = time[3];	
			TimeStruct.hours = time[4];		
			DateStruct.weekday =time[7];
			RTC_ConfigTime(RTC_FORMAT_BIN, &TimeStruct); 
			RTC_ConfigDate(RTC_FORMAT_BIN, &DateStruct); 
}














